package com.fyzk.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tyjc.lottery.R;


public class LotteryCountDown extends LinearLayout{
	
	private LinearLayout ll;
	private TextView phase_tv;
	private TextView endTimeTiShi_tv;
	private TextView endTime_tv;
	private TextView kong_tv;	// 空textview，用来调整期号、时间位置

	private Context context;

	public LotteryCountDown(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		initView(context);
	}
	
	public LotteryCountDown(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		initView(context);
	}
	
	public LotteryCountDown(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		initView(context);
	}
	
	private void initView(Context context){
		this.context = context;
		View view = LayoutInflater.from(context).inflate(R.layout.layout_countdown, null);
		ll = (LinearLayout) view.findViewById(R.id.countDownLayout);
		phase_tv = (TextView) view.findViewById(R.id.lotteryCountDown_qihao_tv);
		endTimeTiShi_tv = (TextView) view.findViewById(R.id.lotteryCountDownTime1);
		endTime_tv = (TextView) view.findViewById(R.id.lotteryCountDownTime);
		kong_tv = (TextView) view.findViewById(R.id.lotteryCountDown_kong_tv);
		initFuZhi();
		LinearLayout.LayoutParams pl = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1);
		view.setLayoutParams(pl);
		this.addView(view);
	}
	
	public void initFuZhi(){
		phase_tv.setText("第 期");
		endTimeTiShi_tv.setText("截止:");
		endTime_tv.setText("正在获取中...");
	}
	
	/**
	 * (横向：LinearLayout.HORIZONTAL;  纵向：LinearLayout.VERTICAL)
	 */
	public void setOrientation(int orientation){
		ll.setOrientation(orientation);
	}
	
	public void setPhase(String phaseStr){
		phase_tv.setText(phaseStr);
	}
	
	public void setPhaseColor(int resId){
		phase_tv.setTextColor(context.getResources().getColor(resId));
	}
	
	public void setEndTime(String endTimeStr){
		endTime_tv.setText(endTimeStr);
	}
	
	public void setEndTimeColor(int resId){
		endTimeTiShi_tv.setVisibility(View.GONE);
		endTime_tv.setTextColor(context.getResources().getColor(resId));
	}

	public void isGaoPin(boolean isGaoPin) {
		if (isGaoPin) {
			kong_tv.setVisibility(GONE);
		} else {
			kong_tv.setVisibility(VISIBLE);
		}
	}
}
